export const toJson = function (a) {
    try {
        if (typeof a === 'string') {
            return JSON.parse(a)
        }
        return JSON.parse(JSON.stringify({...a}))
    } catch (e) {
        return {};
    }
}
export const emptyObj = function (a) {
    if (a == null) {
        return true;
    }
    return JSON.stringify(a) === "{}";
}

export const randomInt = function (min, max) {
    let newVar = [min, max].sort((a, b) => a - b);
    return Math.floor(Math.random() * (newVar[1] - newVar[0] + 1) + newVar[0])
}
export const random = function () {
    return Math.random();
}

export const randomStr = function () {
    let result = '';
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    const charactersLength = characters.length;
    for (let i = 0; i < length; i++) {
        const randomIndex = Math.floor(Math.random() * charactersLength);
        result += characters.charAt(randomIndex);
    }
    return result;
}
